/*
struct ListNode {
	int val;
	struct ListNode *next;
	ListNode(int x) :
			val(x), next(NULL) {
	}
};*/
class Solution {
public:
	ListNode* FindFirstCommonNode(ListNode* pHead1, ListNode* pHead2)
	{
		auto cur1 = pHead1, cur2 = pHead2;
		while (cur1 && cur2)
		{
			cur1 = cur1->next;
			cur2 = cur2->next;
		}
		int step = 0;
		bool is1Longer = true;
		while (cur1)
		{
			cur1 = cur1->next;
			step++;
		}
		while (cur2)
		{
			is1Longer = false;
			cur2 = cur2->next;
			step++;
		}
		cur1 = pHead1, cur2 = pHead2;
		if (is1Longer)
		{
			while (step--) cur1 = cur1->next;
		}
		else while (step--) cur2 = cur2->next;
		while (cur1 != cur2) cur1 = cur1->next, cur2 = cur2->next;
		return cur1;
	}
};
